home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 1 / LSD Compendium Deluxe 1.iso / a / text / manipulation / cv.lha / cv / cvt / numdigits.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-31  |  530 b   |  38 lines

  1. /*
  2.  *  NUMDIGITS.C
  3.  */
  4.  
  5. long numdigits(v,b)
  6. long v,b;
  7. /* computes the maximum #of digits needed to express given value 'v' in
  8.  * a notation with base 'b' */
  9. {
  10.   long r;   /* remainer */
  11.   long n=0; /* #of digits */
  12.  
  13.   if(b>0)
  14.     for(r=v; r>0; r/=b, n++) ;
  15.  
  16.   return n;
  17. }
  18.  
  19.  
  20. #ifdef TEST
  21. main(int ac, char **av)
  22. {
  23.   if(ac<3)
  24.     puts("usage: NUMDIGITS <value> <base>");
  25.  
  26.   else
  27.   {
  28.     long v,b;
  29.  
  30.     v= atol(av[1]);
  31.     b= atol(av[2]);
  32.  
  33.     printf("numdigits(%ld,%ld)= %ld", v,b,numdigits(v,b));
  34.   }
  35.   exit(0);
  36. }
  37. #endif /* TEST */
  38.